//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	TabPageCollection.cs
//  Developer:	Solomatov Igor
//  Created:	14.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.Collections;
using System.Web.UI;

namespace Smart.Common.WebControls
{
	/// <summary>
	/// TabPages collection
	/// </summary>
	public class TabPageCollection : StateManagedCollection
	{
		private static readonly Type[] KnownTypes = {typeof (TabPage)};

		public TabPage this[int index]
		{
			get { return (TabPage) ((IList) this)[index]; }
			set { ((IList) this)[index] = value; }
		}

		public int IndexOf(object value)
		{
			var title = (value is TabPage) ? ((TabPage) value).Title : value.SToStr(string.Empty);

			for (var i = 0; i < Count; i++)
				if (this[i].Title == title)
					return i;

			return -1;
		}

		public int Add(TabPage value)
		{
			var i = IndexOf(value);

			return i < 0 ? ((IList) this).Add(value) : i;
		}

		public void Insert(int i, TabPage v)
		{
			if (IndexOf(v) < 0)
				((IList) this).Insert(i, v);
		}

		public void Remove(object v)
		{
			var i = IndexOf(v);

			if (i >= 0)
				((IList) this).RemoveAt(i);
		}

		protected override Type[] GetKnownTypes()
		{
			return KnownTypes;
		}

		protected override object CreateKnownType(int i)
		{
			return new TabPage();
		}

		protected override void SetDirtyObject(object o)
		{
		}
	}
}